<table id="setting_site_propertygrid" class="easyui-propertygrid"
       data-options="
            border:false,
            fit:true,
            showHeader:true,
            columns:[[{field:'name',title:'属性名称',width:80,sortable:true},{field:'value',title:'属性值',width:200}]],
            showGroup:true,
            scrollbarSize:0,
            title:'系统设置 > 站点设置',
            url:'/admin/setting/site/propertygrid',
            method:'get',
            toolbar:setting_site_propertygrid_toolbar">
</table>

<script type="text/javascript">
var setting_site_propertygrid_id = 'setting_site_propertygrid';
var setting_site_propertygrid_toolbar = [
    { text: '保存', iconCls: 'icons-other-disk', handler: settingSiteSave },
    { text: '刷新', iconCls: 'icons-arrow-arrow_refresh', handler: settingSiteRefresh },
    { text: '恢复默认', iconCls: 'icons-other-cog', handler: settingSiteDefault }
];
//保存
function settingSiteSave(){
    var data = [];
    var rows = $('#'+setting_site_propertygrid_id).propertygrid('getChanges');
    for(var i=0; i<rows.length; i++){
        data.push(rows[i]['key']+'#'+rows[i]['value']);
    }
    $.post('/admin/setting/site', {data: data, _xsrf: $.cookie('_xsrf')}, function(res){
        if(res.code != 0){
            $.messager.alert('提示信息', res.msg, 'error');
        }else{
            $.messager.alert('提示信息', res.msg, 'info');
        }
    }, 'json');
}
//刷新
function settingSiteRefresh(){
    $('#'+setting_site_propertygrid_id).propertygrid('reload');
}
//恢复默认
function settingSiteDefault(){
    $.messager.confirm('提示信息', '确定要恢复出厂设置吗？', function(result){
        if(!result) return true;
        $.post('/admin/setting/site/default', function(res){
            if(!res.status){
                $.messager.alert('提示信息', res.info, 'error');
            }else{
                $.messager.alert('提示信息', res.info, 'info');
                settingSiteRefresh();
            }
        }, 'json');
    })
}
</script>